<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>proxy实例的isExtensible方法</title>
</head>
<body>
  <script>
    // isExtensible() 方法拦截Object.isExtensible() 操作
    var p = new Proxy({}, {
      isExtensible: function (target) {
        console.log('called');
        return true
      }
    });
    Object.isExtensible(p) // 'called' // true
    // 该方法只能返回布尔值，否则返回值会自动转为布尔值
    // 这个方法有一个强限制，它的返回值必须与目标对象的isExtensible属性保持一致，否则会报错。
    // Object.isExtensible(proxy) === Object.isExtensible(target)
    var res = Object.isExtensible({});
    console.log(res) // true 空对象是可扩展的
    var p1 = new Proxy({}, {
      isExtensible: function (target) {
        return false
      }
    });
    Object.isExtensible(p1)
    //// Uncaught TypeError: 'isExtensible' on proxy:
    // trap result does not reflect extensibility of proxy target (which is 'true')
  </script>
</body>
</html>